/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    bool Compare(TreeNode* _left, TreeNode* _right){
        if(_left == nullptr && _right == nullptr) return true;
        // 一个为空，一个不为空
        else if(_left == nullptr || _right == nullptr) return false;
        else if(_left->val != _right->val) return false;  

        bool inside =  Compare(_left->right, _right->left);
        bool outside = Compare(_left->left, _right->right);
        return inside && outside;
    }

    bool isSymmetric(TreeNode* root) {
        return Compare(root->left, root->right);
    }
};